﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace FazaDemo.PL.Wpf
{
    abstract class VisualBuildWorker
    {

        private UIElement _control;

        protected Type _type;

        protected IVisualElemFactory _factory;

        public int RowIndex { get; set; }

        public Grid ParentGrid { get; set; }

        public void Build<T>(int colIndex)
        {
            TypeInit<T>();
            FactoryInit();
            CreateWork(colIndex);
        }

        private void TypeInit<T>()
        {
            _type = typeof(T);
        }

        protected abstract void FactoryInit();

        private void CreateWork(int colIndex)
        {
            _control = _factory.Create();
            InstallElem(colIndex);
        }

         private void InstallElem(int colIndex)
        {
            ParentGrid.Children.Add(_control);
            Grid.SetColumn(_control, colIndex);
            Grid.SetRow(_control, RowIndex);
        }

    }
}
